class Iterator {
    constructor(list) {
        this._list = list
        this._index = 0
    }

    next() {
        if(!this.hasNext()) {
            return null
        }
        return this._list[this._index++]
    }

    hasNext() {
        return this._index < this._list.length
    }
}

function test() {
    const iterator = new Iterator([1, 2, 3, 4, 5])

    while(iterator.hasNext()) {
        console.log('迭代：', iterator.next())
    }
}

console.log('----------------迭代器模式-------------------')
test()